<template>
	<view class="page" style="padding-bottom: 50rpx;">
		<view class="topVue">
			<view class="safeVue" :style="{ height: statusBarHeight + 'rpx' }"></view>
			<view class="flex align-center padding-row30" :style="{ height: barHeight + 'rpx', top: statusBarHeight + 'rpx' }" @click="$tools.back()">
				<image src="../../static/back.png" style="width: 48rpx; height: 48rpx;"></image>
				<text style="line-height: 1; color: #454545; font-weight: 600; font-size: 32rpx; padding-left: 20rpx;">订单支付</text>
			</view>
		</view>
		<view :style="{ height: statusBarHeight + barHeight + 'rpx' }"></view>
		
		<view class="conVue flex-wrap flex-between margin0">
			<view class="li" v-for="(item, index) in imgs" :key="index" @click="$tools.openimg(item)">
				<image :src="item" style="width: 100%; height: 100%; border-radius: 20rpx;"></image>
			</view>
			<view class="li relative" @click="choose()" v-if="imgs.length<4">
				<text class="absolute-auto" style="line-height: 1; font-size: 60rpx;">+</text>
			</view>
		</view>
		<view class="item margin20 flex-between align-center padding-row30">
			<text style="color: #454545; font-weight: 600; line-height: 1;">上门时间</text>
			<text style="color: #454545; font-weight: 600; line-height: 1; padding-right: 20rpx;">{{ detail.visitTime }}</text>
		</view>
		<view class="item margin20 flex-between align-center padding-row30">
			<text style="color: #454545; font-weight: 600; line-height: 1;">完成时间</text>
	
			<text style="color: #454545; font-weight: 600; line-height: 1; padding-right: 20rpx;">{{ detail.updateTime }}</text>
				
		</view>
		<textarea placeholder="完成说明" v-model="detail.description" disabled></textarea>
		
		<view class="item margin20 flex-between align-center padding-row30">
			<text style="color: #454545; font-weight: 600; line-height: 1;">剩余服务费金额</text>
			<text style="color: #D37430; font-weight: 600; line-height: 1;">{{detail.price - detail.deposit}}</text>
		</view>
		
		<view class="btn margin50" v-if="detail.state==2" @click="submitDone()">开始支付</view>
		
		
		
		<u-picker v-model="show" mode="time" :params="params" @confirm="confirm"></u-picker>
		<u-picker v-model="show0" mode="time" :params="params" @confirm="confirm0"></u-picker>
	</view>
</template>

<script>
	import url from "@/common/url.js"
	import { mapState } from "vuex"
	export default {
		data(){
			return {
				statusBarHeight: 0,
				barHeight: 0,
				detail: {
					price: 0,
					deposit: 0,
					state: null
				},
				imgs: [],
				show: false,
				show0: false,
				params: {
					year: true,
					month: true,
					day: true,
					hour: true,
					minute: true,
					second: false
				},
			}
		},
		onLoad(option) {
			this.orderId = option.value
			console.log("kkkk", this.orderId)
			let that = this;
			wx.getSystemInfo({
				success(res) {
					let deviceWidth = wx.getSystemInfoSync().windowWidth
					that.statusBarHeight = Number(res.statusBarHeight) * ( 750 / deviceWidth ) 
					let menuButtonInfo = wx.getMenuButtonBoundingClientRect()
					let barHeight = menuButtonInfo.height + (menuButtonInfo.top - res.statusBarHeight) * 2
					that.barHeight = Number(barHeight) * ( 750 / deviceWidth )
				},
			});
			this.getDetail()
		},
		
		computed: {
			...mapState({
				user: state=> state.user
			})
		},
		
		methods: {
			getDetail(){
				this.$request(`/api/WeChat/homecareOrderDetail?id=${this.orderId}`, {}, "GET").then(res=>{
					if(res.code===200){
						console.log("kk", res)
						this.detail = res.data
						this.imgs = this.detail.imgUrl.split(",")
					}
				})
			},
			// 上传图片
			choose(){
				this.$utils.choose().then(res=>{
					console.log(res)
					uni.showLoading()
					let _this = this
					uni.uploadFile({
						url: `${url.url}/api/WeChat/wechatUpload`,
						filePath: res.tempFilePaths[0],
						name: "file",
						header:{
							"token": uni.getStorageSync("token")
						},
						success: (result) => {
							console.log(result)
							uni.hideLoading()
							let data = JSON.parse(result.data)
							_this.imgs.push(data.data)
							console.log(_this.imgs)
						},
						fail(err) {	
							console.log(err)
							uni.hideLoading()
						}
					})
				})
			}, 
			
			// 完成订单
			async submitDone(){
				const res = await this.$request(`/api/WeChat/userHomecareFinish?orderId=${this.orderId}`, {
					orderId: this.orderId,
				}, "POST")
				if(res.code==200) {
					console.log(res)
					this.$u.toast("操作成功")
					setTimeout(()=>{
						this.$tools.back(1)
					}, 1000)
				}
			},
			
			confirm(e){
				console.log(e)
				this.time = `${e.year}-${e.month}-${e.day} ${e.hour}:${e.minute}`
			},
			confirm0(){
				console.log(e)
				this.time0 = `${e.year}-${e.month}-${e.day} ${e.hour}:${e.minute}`
			},
		}
	}
</script>

<style lang="less" scoped>
	.topVue {
		width: 100%;
		background: #fff;
		position: fixed;
		left: 0;
		top: 0;
		z-index: 99;
		.safeVue {
			width: 100%;
		}
	}
	
	.conVue {
		width: 690rpx;
		.li {
			width: 330rpx;
			height: 330rpx;
			border-radius: 20rpx;
			box-shadow: 0rpx 0rpx 16rpx 0rpx rgba(178, 178, 178, 0.25), inset 0rpx 8rpx 8rpx 0rpx rgba(255, 255, 255, 0.25);
			position: relative;
			margin-top: 20rpx;
		}
	}
	
	textarea {
		width: 690rpx;
		height: 200rpx;
		background: #f5f5f5;
		border-radius: 15rpx;
		display: block;
		box-sizing: border-box;
		padding: 20rpx;
		color: #333;
		margin: 20rpx auto 0;
	}
	.item {
		width: 690rpx;
		height: 92rpx;
		border-radius: 20rpx;
		box-shadow: 0rpx 0rpx 16rpx 0rpx rgba(178, 178, 178, 0.25), inset 0rpx 8rpx 8rpx 0rpx rgba(255, 255, 255, 0.25);
		position: relative;
	}
	.btn {
		width: 520rpx;
		height: 88rpx;
		background: #D37430;
		border-radius: 12rpx;
		line-height: 88rpx;
		text-align: center;
		color: #fff;
	}
</style>